<?php
class AuthController extends Zend_Controller_Action
{

    public function loginAction()
    {

	     //$config = new Zend_Config_Ini(APPLICATION_PATH.'/configs/application.ini', 'staging');
        //$db = $this->_getParam('db');
		  //$db = Zend_Db::factory($config->database);

        $loginForm = new Application_Form_Auth_Login();

			$authNamespace = new Zend_Session_Namespace('Zend_Auth');

			if ( !empty ( $authNamespace->user ) ) {
				$this->_redirect('/');
				return;
			}

        if ($loginForm->isValid($_POST)) {
				if ( $user = Application_Model_User::Auth( $loginForm->getValue('username'), $loginForm->getValue('password') ) ) 
				{
					$authNamespace->user = $user->getId();
					$this->_redirect('/');
					return;
				}
        } 

        $this->view->loginForm = $loginForm;

    }

	 public function logoutAction()
	 {
		 $authNamespace = new Zend_Session_Namespace('Zend_Auth');
		 unset( $authNamespace->user );
		 $this->_redirect('/auth/login');
		 return;
	 }

}